﻿@using Apps.Web.Core;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<div class="mvctool">
   <input id="txtQuery" placeholder="请输入关键字" type="text" class="searchText" />
    @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query,ref perm, "Query", true)
    @Html.ToolButton("btnCreate", "fa fa-plus", Resource.Create,ref perm, "Create", true)
    @Html.ToolButton("btnEdit", "fa fa-pencil", Resource.Edit,ref perm, "Edit", true)
    @Html.ToolButton("btnDetails", "fa fa-list", Resource.Details,ref perm, "Details", true)
    @Html.ToolButton("btnDelete", "fa fa-trash", Resource.Delete,ref perm, "Delete", true)
</div>
<table id="List"></table>

<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>

<script type="text/javascript">
    $(function () {
        $('#List').datagrid({
            url: '@Url.Action("GetList")',
            width: SetGridWidthSub(10),
            methord: 'post',
            height:  SetGridHeightSub(37),
            fitColumns: true,
            sortName: 'Id',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            rownumbers: true,//行号
            onLoadSuccess: function (data) {
                $(".datagrid-row td div").addClass("exceed");
                $('#List').datagrid("resize");
            },
            columns: [[
                { field: 'Id', title: 'ID', width: 80, hidden: true },
                { field: 'Title', title: '字段标题', width: 80, sortable: true },
                { field: 'Name', title: '字段英文名称', width: 80, sortable: true },
                { field: 'AttrType', title: '类型', width: 80, sortable: true },
                { field: 'CheckRule', title: '校验规则', width: 80,  sortable: true,formatter:function(value){
                    var rules = "";
                    if(value!=null)
                    {
                        if(value.indexOf("NotNull")>-1)
                        {
                            rules = "&nbsp;<span class='label label-success'>非空</span>";
                        }
                        if(value.indexOf("IsDate")>-1)
                        {
                            rules =rules+"&nbsp;<span class='label label-error'>日期</span>";
                        }
                        if(value.indexOf("IsNaN")>-1)
                        {
                            rules =rules+"&nbsp;<span class='label label-info'>数字</span>";
                        }
                    }
                    return rules;
                }},
                 { field: 'OptionList', title: '默认值', width: 80, sortable: true },
                { field: 'CheckJS', title: '校验脚本', width: 80, sortable: true, hidden: true },
                { field: 'TypeName', title: '所属类别', width: 80, sortable: true },
                { field: 'CreateTime', title: '创建时间', width: 80, sortable: true }
            ]]
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").datagrid('load');
        else
            $("#List").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnExport").click(function () {
            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0'' src='/SysHelper/ReportControl'></iframe>");
            $("#modalwindow").window({ title: Lang.Export, width: 320, height: 200, iconCls: 'fa fa-plus' }).window('open');
        });
        $("#btnCreate").click(function () {
            $.modalWindow(Lang.Create, '@Url.Action("Create")', 650, 550, 'fa fa-plus');
        });
        $("#btnEdit").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.modalWindow(Lang.Edit, '@Url.Action("Edit")?id=' + row.Id + '&Ieguid=' + GetGuid(), 700, 500, 'fa fa-pencil');
            } else { $.messageBox5s(Lang.Tip, Lang.PleaseSelectTheOperatingRecord); }
        });
        $("#btnDetails").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.modalWindow(Lang.Details, '@Url.Action("Details")?id=' + row.Id + '&Ieguid=' + GetGuid(), 500, 300, 'fa fa-list');
            } else { $.messageBox5s(Lang.Tip, Lang.PleaseSelectTheOperatingRecord); }
        });
        $("#btnQuery").click(function () {
            var queryStr = $("#txtQuery").val();
            if (queryStr == null) {
                queryStr = "%";
            }
            $("#List").datagrid("load", { queryStr: encodeURI(queryStr) });

        });
        $("#btnDelete").click(function () {
            dataDelete("@Url.Action("Delete")", "List");
	    });
        $(window).resize(function () {
            $('#List').datagrid('resize', {

            }).datagrid('resize', {
                width: SetGridWidthSub(10),
                height: SetGridHeightSub(37)
            });
        });
    });
</script>
